﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using Ahis.Demo.Backend.Contracts;

namespace Ahis.Demo.Backend
{
    public class PassengerService : IPassengerService
    {
        #region IPassengerService Members

        public List<Flight> GetFlights()
        {
            // Create a connection to the database
            AhisModelContainer DataContext = new AhisModelContainer();

            // Retrieve the data
            var Flights = from f in DataContext.FlightSet
                          select f;

            // Return the data
            return Flights.ToList();
        }

        public PassengerForFlightResponse GetPassengerForFlights(PassengerForFlightRequest request)
        {
            // Create a connection to the database
            AhisModelContainer DataContext = new AhisModelContainer();

            // Retrieve the data
            var Results = from p in DataContext.PassengerSet
                          where p.Flight.FlightNr == request.FlightNr
                          select p;

            return new PassengerForFlightResponse()
            {
                Passengers = Results.ToList()
            };
        }

        #endregion
    }
}
